Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shimmer

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shimmer

Safe(r) monkeypatching for JavaScript.

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.8M
increased by2.5%
Maintainers
1
Weekly downloads
 
Created

What is shimmer?

The shimmer npm package is a utility for wrapping and replacing object properties and methods, primarily used for monkey-patching - a technique to modify or extend the behavior of libraries or objects in a dynamic way. It allows developers to intercept and modify the behavior of functions in a non-intrusive manner, which is particularly useful for logging, monitoring, and testing purposes.

What are shimmer's main functionalities?

Wrapping a function

This code demonstrates how to use shimmer to wrap a function. It intercepts calls to the original function, allowing you to execute code before and after the original function is called.

const shimmer = require('shimmer');

function originalFunction() {
  console.log('Original function');
}

shimmer.wrap(originalFunction, function(original) {
  return function() {
    console.log('Before original function');
    original.apply(this, arguments);
    console.log('After original function');
  };
});

originalFunction();

Replacing a method of an object

This example shows how to use shimmer to replace a method of an object. It allows you to run custom code before and after the original method is executed, effectively modifying its behavior.

const shimmer = require('shimmer');

const myObject = {
  myMethod: function() {
    console.log('Original method');
  }
};

shimmer.wrap(myObject, 'myMethod', function(original) {
  return function() {
    console.log('Before original method');
    original.apply(this, arguments);
    console.log('After original method');
  };
});

myObject.myMethod();

Other packages similar to shimmer

Keywords

FAQs

Package last updated on 17 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc